package com.zk.manager.config;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.fastjson.JSON;
import com.zk.common.entity.R;
import org.springframework.context.annotation.Configuration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@Configuration
public class SentinelConfig implements BlockExceptionHandler {
	@Override
	public void handle(HttpServletRequest httpServletRequest, HttpServletResponse response, BlockException e) throws Exception {
		response.setContentType("text/html;charset=utf8");
		R r = R.error().message("出现了限流异常！（自定义限流处理）");
		response.getWriter().println(JSON.toJSONString(r));
		response.getWriter().flush();
	}
}
